package com.hustcad.plm.pdm.preview.util;

import cn.hutool.core.collection.CollUtil;
import com.hustcad.plm.pdm.preview.enums.PreviewErrorCodeEnum;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class PreviewUtils {
    private static final String PREVIEW_MODEL_WEB_PDF = "preview.web.pdf";
    private static final String PREVIEW_MODEL_WEB_HTML = "preview.web.html";
    private static final String PREVIEW_MODEL_WEB_LUCKY_SHEET = "preview.web.luckysheet";
    private static final String PREVIEW_MODEL_WEB_INTEVUE = "preview.web.intevue";
    private static final String PREVIEW_MODEL_WEB_VIDEO = "preview.web.video";
    private static final String PREVIEW_MODEL_WEB_IMAGE = "preview.web.image";
    private static final String PREVIEW_MODEL_WEB_TIF = "preview.web.tif";
    private static final String PREVIEW_MODEL_WEB_DSN = "preview.web.dsn";
    private static final String PREVIEW_MODEL_WEB_PCB = "preview.web.pcb";
    private static final String PREVIEW_MODEL_CLIENT_PLUGIN = "preview.web.plugin";
    @Value("${preview.web.pdf:pdf}")
    private List<String> previewWebPdf;
    @Value("${preview.web.html:html}")
    private List<String> previewWebHtml;
    @Value("${preview.web.luckysheet:xlsx,xls}")
    private List<String> previewWebLuckysheet;
    @Value("${preview.web.intevue:iwa,iwp,svgz,zip}")
    private List<String> previewWebIntevue;
    @Value("${preview.web.video:ogg,mp4,webm}")
    private List<String> previewWebVideo;
    @Value("${preview.web.image:jpg,jpeg,png,bmp,gif,jfif}")
    private List<String> previewWebImage;
    @Value("${preview.web.tif:tif,tiff}")
    private List<String> previewWebTif;
    @Value("${preview.web.dsn:edf,edfi}")
    private List<String> previewWebDsn;
    @Value("${preview.web.pcb:tgz,xml}")
    private List<String> previewWebPcb;
    @Value("${preview.client.plugin:pdf,iva,ivp,ivg,ivx,i3dAsm,JPG,png,edif,dwg,iwa,iwp,iwx,jpg,jpeg,prt,svgz,bmp,tyc,docx,doc,mi}")
    private List<String> previewClientPlugin;

    public List<String> buildPreviewFileSuffix(String previewConstant) {
        List<String> fileExtList = new ArrayList();
        if ("webViewFormat".equalsIgnoreCase(previewConstant)) {
            CollUtil.addAllIfNotContains(fileExtList, this.previewWebPdf);
            CollUtil.addAllIfNotContains(fileExtList, this.previewWebHtml);
            CollUtil.addAllIfNotContains(fileExtList, this.previewWebIntevue);
            CollUtil.addAllIfNotContains(fileExtList, this.previewWebVideo);
            CollUtil.addAllIfNotContains(fileExtList, this.previewWebImage);
            CollUtil.addAllIfNotContains(fileExtList, this.previewWebTif);
            CollUtil.addAllIfNotContains(fileExtList, this.previewWebLuckysheet);
            CollUtil.addAllIfNotContains(fileExtList, this.previewWebDsn);
            CollUtil.addAllIfNotContains(fileExtList, this.previewWebPcb);
        } else {
            if (!"clientViewFormat".equalsIgnoreCase(previewConstant)) {
                throw PreviewErrorCodeEnum.PREVIEW_CONSTANT_EMPTY.getException(new Object[0]);
            }

            CollUtil.addAllIfNotContains(fileExtList, this.previewClientPlugin);
        }

        return fileExtList;
    }
}